/**********
This library is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)

This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for
more details.

You should have received a copy of the GNU Lesser General Public License
along with this library; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
**********/
// H264VideoServerMediaSubsession.hh
// H.264视频服务器媒体子会话头文件
#ifndef _H264_VIDEO_SERVER_MEDIA_SUBSESSION_HH
#define _H264_VIDEO_SERVER_MEDIA_SUBSESSION_HH

#include <liveMedia.hh>
#include <StreamReplicator.hh>
#include <GroupsockHelper.hh>
#include "service/IMediaStreamHandler.hh"

// 前向声明
class IMediaStreamHandler;
class StreamReplicator;
class T32H264LiveSource;

class H264VideoServerMediaSubsession : public OnDemandServerMediaSubsession {
public:
    // 创建新的H.264视频子会话（使用共享的StreamReplicator）
    static H264VideoServerMediaSubsession* createNew(UsageEnvironment& env,
                                                     StreamReplicator* replicator,
                                                     IMediaStreamHandler* handler,
                                                     Boolean reuseFirstSource = False);

protected:
    H264VideoServerMediaSubsession(UsageEnvironment& env,
                                   StreamReplicator* replicator,
                                   IMediaStreamHandler* handler,
                                   Boolean reuseFirstSource);
    
    // 析构函数
    virtual ~H264VideoServerMediaSubsession();
    
    // 生成SDP辅助行
    virtual char const* getAuxSDPLine(RTPSink* rtpSink, FramedSource* inputSource);
    
    // 创建视频源
    virtual FramedSource* createNewStreamSource(unsigned clientSessionId, unsigned& estBitrate);
    
    // 创建RTP接收器
    virtual RTPSink* createNewRTPSink(Groupsock* rtpGroupsock, unsigned char rtpPayloadTypeIfDynamic, FramedSource* inputSource);
    
    // 检查是否需要延迟会话开始
    virtual Boolean shouldDelayBeginningOfSession() const;
    
    // 关闭流源（重写以避免关闭共享源）
    virtual void closeStreamSource(FramedSource* inputSource);
    
private:
    // 成员变量
    IMediaStreamHandler* fHandler;       // 视频处理器接口（提供SPS/PPS）
    StreamReplicator* fReplicator;       // Live555 stream replicator（负责多客户端分发）
    char const* fAuxSDPLine;             // SDP辅助行
    Boolean fReuseFirstSourceFlag;       // 保存 reuseFirstSource 标志（因为基类的 fReuseFirstSource 是私有的）
};

#endif // _H264_VIDEO_SERVER_MEDIA_SUBSESSION_HH

